package com.example.common.util.utils;

import java.util.Random;

/**
 * @Author juzipi
 * @Date 2021/7/18 11:26
 * @Info
 */
public class RandomUtils {



    /**
     * 随机数字验证码
     * @param charCount 长度
     * @return 随机数字验证码
     */
    public static String captcha(int charCount){
        StringBuilder charValue = new StringBuilder();
        for (int i = 0; i < charCount; i++) {
            char c = (char) (randomInt(0, 10) + '0');
            charValue.append(c);
        }
        return charValue.toString();
    }


    /**
     * 随机数
     */
    public static int randomInt(int from, int to) {
        Random r = new Random();
        return from + r.nextInt(to - from);
    }

}
